home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
ljl.exe
/
LJL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-12
|
11KB
|
355 lines
/*************************************************************************
* This program is a combination of the Comp-U-Serve files
* SHADE.TXT
* SPU12.ARC
*
* along with modifications for printing C source code on a
* LaserJet Series II.
*
* Since the source and suggestions were public domain, this file and
* source are released to public domain.
*
* The source code is for Microsoft C 6.0.
*
* As was said in the files used to create this program: Enjoy !!!
*
*------------------------------------------------------------------------
*
* Modified: V1.4 12-Sep-92 by Bob Withers - bwit@delphi.com
* bwithers@kdsi.com
*
* o Corrected problem that would fail file open if the filename
* provided was not in the current directory. (i.e. LJL A:*.C).
*
* o Removed all DOS specific code and replaced with my portable
* directory search routines. These directory routines are
* copyrighted by me, however I grant permission for them to be
* copied and used in any way as long as my copyright statement
* is not removed.
*
* o Modified to use only functions defined by ANSI Standard C.
*
* o Cleaned up the structure of the code (my opinion).
*
* o This code has been compiled using Microsoft C/C++ V7.0. It
* has been compiled as both C and C++ code without errors or
* warnings.
*
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "portdir.h"
#define PATH_SEP '\\'
#define DRIVE_SEP ':'
static void BuildPathName(char *pszFilePath, char *pszPath,
char *pszName);
static void blurb(void);
static void detab(char *str);
static void get_fdate(time_t *pTime, char *dstr, int nLen);
static void heading(char *fname, int page, char *dstr);
static void prn_cmd(char *cmd);
static void usage(void);
static void shade(void);
static void check_line_count(char *pszName);
/*************************************************************************
Commands for:
---------------------------------------------------------------
H P L A S E R J E T S E R I E S I I L A N D S C A P E
---------------------------------------------------------------
**************************************************************************/
#define LPP 57 /* Lines Per Page */
#define HMW 106 /* Header Maximum Width */
#define PNAME "HPLJ II (landscape)" /* printer description */
#define SEPCHAR 0xB3 /* sep line #'s from text */
#define TMW 88 /* Text Maximum Width */
char HDRFONT[] = {0x1B, 0x28, 0x73, 0x33, 0x54, /* courier font */
0x1B, 0x26, 0x6B, 0x30, 0x53, 0x00}; /* 10 pitch */
char NO_ULINE[] = {0x1B, 0x26, 0x64, 0x40, 0x00}; /* underline off */
char RESET[] = {0x1B, 0x45, 0x00}; /* reset printer */
char SETUP[] = {0x1B, 0x28, 0x31, 0x30, 0x55, /* IBM PC char set */
0x1B, 0x26, 0x6C, 0x31, 0x4F, /* landscape */
0x1B, 0x26, 0x6C, 0x38, 0x44, 0x00}; /* 8 lines per inch*/
char TXTFONT[] = {0x1B, 0x26, 0x6B, 0x32, 0x53, 0x00}; /* lineprinter font*/
char ULINE[] = {0x1B, 0x26, 0x64, 0x44, 0x00}; /* underline on */
#define MAXCHAR 512 /* Maximum number of chars per record */
#define OFF 0
#define ON 1
#define TABVAL 3 /* Tab stops every 3 characters */
#define VERSION "1.4"
static char inrec[2 * MAXCHAR], date[16];
static int len, line, linesout, pnum, status;
/***********************************************************************/
int main(int argc, char **argv)
{
auto FILE *fpin;
auto DIR *pDir;
auto struct dirent *pDirEnt;
auto char szFilePath[FILENAME_MAX + 1];
blurb();
if (argc<2)
{
usage();
exit(0);
}
fflush(stdprn);
prn_cmd(RESET);
prn_cmd(SETUP);
while (--argc)
{
pDir = opendir(*++argv);
if (NULL == pDir)
continue;
while (NULL != (pDirEnt = readdir(pDir)))
{
BuildPathName(szFilePath, *argv, pDirEnt->d_name);
if ((fpin = fopen(szFilePath, "r")) != NULL)
{
fprintf(stdprn, "\033&a+0L"); /* start with zero left margin */
line = linesout = pnum = 0; /* initialize counters */
get_fdate(&pDirEnt->d_datetime, date, sizeof(date));
strupr(*argv);
while (fgets(inrec, MAXCHAR, fpin) != NULL)
{
line++;
detab(inrec);
len = strlen(inrec);
if (pnum == 0)
check_line_count(pDirEnt->d_name);
fprintf(stdprn, "%4d%c %.*s\r", line, SEPCHAR,
TMW - 7, inrec);
linesout++;
check_line_count(pDirEnt->d_name);
while (len > (TMW - 7))
{
memmove(inrec, &inrec[TMW - 7], len - (TMW - 8));
len = strlen(inrec);
if ((linesout % LPP) !=0)
fprintf(stdprn, "\n");
fprintf(stdprn, " %c %.*s\r", SEPCHAR,
TMW - 7, inrec);
linesout++;
check_line_count(pDirEnt->d_name);
}
printf("%s line %d...\r", pDirEnt->d_name, line);
}
fprintf(stdprn,"\f");
printf("%s done, %d page%s printed.\n", pDirEnt->d_name,
pnum, pnum > 1 ? "s" : "");
fclose(fpin);
}
else
printf("%s - unable to open.\n", pDirEnt->d_name);
}
}
prn_cmd(RESET);
return(0);
}
/***********************************************************************/
static void BuildPathName(char *pszFilePath, char *pszPath, char *pszName)
{
auto int nLen;
nLen = strlen(strcpy(pszFilePath, pszPath));
while (--nLen >= 0)
{
if (PATH_SEP == pszFilePath[nLen] || DRIVE_SEP == pszFilePath[nLen])
{
strcpy(&pszFilePath[nLen + 1], pszName);
return;
}
}
strcpy(pszFilePath, pszName);
return;
}
/***********************************************************************/
static void blurb(void)
{
printf("HP LaserJet II - Source Print Utility - version %s (%s)\n",
VERSION, __DATE__);
printf("<<< configured for %s >>>\n\n",PNAME);
return;
}
/************************************************************************
* routine to test the string for tabs and non-printing ASCII chars and
* terminate string with a NULL
************************************************************************/
static void detab(char *str)
{
auto int cntin, cntout;
auto char tmpstr[2 * MAXCHAR];
cntin = cntout = 0;
while (cntin < (MAXCHAR + 1) && str[cntin] != '\0' && str[cntin] != '\n')
{
if (str[cntin] > 0x1F && str[cntin] < 0x7F) /* printing chars */
strcpy(&tmpstr[cntout++], &str[cntin++]);
else
{
switch (str[cntin])
{
case '\t': /* check for tab character */
tmpstr[cntout++] = ' '; /* TAB, fill with spaces */
while (cntout % TABVAL)
tmpstr[cntout++] = ' ';
cntin++;
break;
default:
tmpstr[cntin++] = 0x2; /* print smiley face */
cntout++;
break;
}
}
}